//
//  NSObject+TextSize.m
//  ZLParty
//
//  Created by uplooking on 2017/7/26.
//  Copyright © 2017年 RenLong. All rights reserved.
//

#import "NSObject+TextSize.h"

@implementation NSObject (TextSize)

- (CGFloat)heightByStringContent:(NSString *)string andLabelWidth:(CGFloat)width andFontSize:(CGFloat)fontSize
{
    UIFont * tfont = [UIFont systemFontOfSize:fontSize];
    //高度估计文本大概要显示几行，宽度根据需求自己定义。 MAXFLOAT 可以算出具体要多高
    CGSize size =CGSizeMake(width,CGFLOAT_MAX);
    //    获取当前文本的属性
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
    //ios7方法，获取文本需要的size，限制宽度
    CGSize  actualsize =[string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
    
    return actualsize.height;
}

- (CGFloat)heightByStringBlodContent:(NSString *)string andLabelWidth:(CGFloat)width andFontSize:(CGFloat)fontSize{
    
    UIFont * tfont = [UIFont boldSystemFontOfSize:fontSize];
    //高度估计文本大概要显示几行，宽度根据需求自己定义。 MAXFLOAT 可以算出具体要多高
    CGSize size =CGSizeMake(width,CGFLOAT_MAX);
    //    获取当前文本的属性
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
    //ios7方法，获取文本需要的size，限制宽度
    CGSize  actualsize =[string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
    
    return actualsize.height;
    
    
}

- (CGFloat)widthByStringContent:(NSString *)string andFontSize:(CGFloat)size
{
    
    CGFloat w = 0.0f;
    
    w = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:size]} context:nil].size.width;
    
    return w;
}

- (CGFloat)widthByAttributedStringContent:(NSAttributedString *)string
{
    CGFloat w = 0.0f;
    
    w = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.width;
    
    return w;
}

- (CGFloat)heightFunctionViewInitWithCount:(NSInteger)count cycle:(NSInteger)cycle everyHeight:(CGFloat)everyHeight{

    CGFloat height = 0;
    
    if (count % cycle == 0) {
        
        height = count/cycle * everyHeight * kAutoScanleX;
        
    }else{
        
        height = (count/cycle + 1) * everyHeight * kAutoScanleX;
    }
    
    return height;
}
@end
